<cfparam name="Order_ID" type="numeric" default="0" />
<cfparam name="Order_UID" type="string" default="" />
<cfparam name="returnUI" type="string" default="orders" />
<cfscript>
	ui = "order";
	view = "form";
	obj = "order";
	if (Len(Order_UID) gt 6) {
		qOrder = request.orderGateway.query(Order_UID = Order_UID);
		Order_ID = qOrder.Order_ID;
	}
	order = request.orderGateway.get(Order_ID = Order_ID);
</cfscript>

<cfif IsNumeric(order.getOrder_ID())>

	<cfscript>
		statuses = request.Base.getOrderStatuses();
		institutionTypes = request.base.getInstitutionTypes();
		institutions = request.gateway.call(objType = "view", obj = "getInstitutions");
		highSchools = request.gateway.call(objType = "view", obj = "getHighSchools");
		cities = request.gateway.call(objType = "view", obj = "getCities");
		states = request.gateway.call(objType = "view", obj = "getStates");
		if (order.getOrder_ID() eq 0) {
			order.setState("CA");
			products = request.productGateway.query(Active = 1);
		} else {
			products = request.orderProductGateway.query(Order_ID = order.getOrder_ID(), Deleted = 0);
		}
		trackings = request.trackingGateway.query(Order_ID = order.getOrder_ID(), Deleted = 0);
		hiddenCategories = "6,7,9,10";
	</cfscript>
	
	<script src="/assets/jquery.validator/dist/jquery.validate.min.js" type="text/javascript"></script>
	<script src="/assets/jquery.validator/dist/additional-methods.min.js" type="text/javascript"></script>
		
	<script type="text/javascript" language="javascript">
	<!--
		<cfoutput>
			var orderID = #order.getOrder_ID()#;
			var status = "#order.getStatus()#";
			var institutionType = "#order.getInstitution_Type()#";
			var statuses = #SerializeJSON(statuses)#;
			var instituionTypes = #SerializeJSON(institutionTypes)#;
			var productQuantityRules;
		</cfoutput>
		var validatorConfig = {
			debug: false,
			rules: {
				Order_ID: {required: true, digits: true, min: 0},
				Institution_ID: {required: true, digits: true, min: 0},
				Status: {required: true},
				First_Name: {required: true},
				Last_Name: {required: true},
				Email: {required: true, email: true},
				Phone: {required: true, phoneUS: true},
				Institution_Type: {required: true},
				College_University_ID: {
					required: {depends: function(elements) {return $("#Institution_Type").val() == "College University"}}
				},
				High_School_ID: {
					required: {depends: function(elements) {return $("#Institution_Type").val() == "High School"}}
				},
				Institution: {
					required: {depends: function(elements) {return parseInt($("#Institution_ID").val()) == 0}}
				},
				Address1: {required: true},
				City: {required: true},
				State: {required: true},
				Zip_Code: {
					required: true, 
					digits: true, 
					minlength: 5, 
					maxlength: 5
				},
				Order_Product_ID: {required: true},
				Product_ID: {required: true}		
			},
			messages: {
				Order_ID: "Required",
				Institution_ID: "Required",
				Status: "Required",
				First_Name: "Required",
				Last_Name: "Required",
				Email: {
					required: "Required",
					email: "Invalid"
				},
				Phone: {
					required: "Required",
					phoneUS: "Invalid - ###-###-####"
				},
				Institution_Type: "Required",
				College_University_ID: "Required",
				High_School_ID: "Required",
				Institution: "Required",
				Address1: "Required",
				City: "Required",
				Zip_Code: {
					required: "Required",
					digits: "Invalid - 5 digits",
					minlength: "Invalid - 5 digits",
					maxlength: "Invalid - 5 digits",
				},
				Order_Product_ID: "Required",
				Product_ID: "Required",
			},
			onsubmit: true,
			onfocusout: false,
			onkeyup: false,
			onclick: false,
			submitHandler: function(form) {
				var valid = true;
				var errorMessages = [];
				var products = $(".productID");
				var totalQuantity = 0;
				for (var p=0; p<products.length; p++) {
					var product = $(products[p]);
					var productID = product.val();
					var quantity = parseInt($("#Quantity_" + productID).val());
					var quantityShipped = parseInt($("#Quantity_Shipped_" + productID).val());
					if (!isInt(quantity)) {
						valid = false;
						errorMessages.push("Quantity is required for every item - enter 0 for none");
					} else if (!isInt(quantityShipped)) {
						valid = false;
						errorMessages.push("Quantity Shipped is required for every item - enter 0 for none");
					}
					if (quantity > 0 || quantityShipped > 0) {
						var productQuantityRule = productQuantityRules[productID];
						if (isInt(productQuantityRule.MAXIMUM)) {
							if (quantity > parseInt(productQuantityRule.MAXIMUM)) {
								valid = false;
								errorMessages.push("Quantity for " + productQuantityRule.PRODUCT + " is over the maximum of " + parseInt(productQuantityRule.MAXIMUM));
							}
							if (quantityShipped > parseInt(productQuantityRule.MAXIMUM)) {
								valid = false;
								errorMessages.push("Quantity Shipped for " + productQuantityRule.PRODUCT + " is over the maximum of " + parseInt(productQuantityRule.MAXIMUM));
							}
						}
						if (isInt(productQuantityRule.INCREMENT)) {
							if (quantity % parseInt(productQuantityRule.INCREMENT) !== 0) {
								valid = false;
								errorMessages.push("Quantity for " + productQuantityRule.PRODUCT + " is not an increment of " + parseInt(productQuantityRule.INCREMENT));
							}
							if (quantityShipped % parseInt(productQuantityRule.INCREMENT) !== 0) {
								valid = false;
								errorMessages.push("Quantity Shipped for " + productQuantityRule.PRODUCT + " is not an increment of " + parseInt(productQuantityRule.INCREMENT));
							}
						}
						totalQuantity = totalQuantity + parseInt(quantity);
					}
				}
				if (totalQuantity == 0) {
					valid = false;
					errorMessages.push("No items in order");
				}
				if (!valid) {
					var errorMessage = "";
					for (i in errorMessages) {
						errorMessage += errorMessages[i] + "\n";
					}
					alert(errorMessage);
				} else {
					form.submit();
				}
			},
			focusCleanup: false,
			errorPlacement: function(error, element) {
				$(element).prev("label").children("span").remove();
				error.appendTo(element.prev("label"));
				//$(element).prev("label").children("span");
			},
			errorElement: "span",
			errorClass: "label label-danger",
			validClass: "label label-info",
			highlight: function(element, errorClass, validClass) {
				$(element).prev("label").children("span").removeClass(validClass).addClass(errorClass);
			},
			unhighlight: function(element, errorClass, validClass) {
				$(element).prev("label").children("span").removeClass(errorClass).addClass(validClass);
			}
		};
		var toggleInstitution = function() {
			var instType = $("#Institution_Type").val();
			if (instType == "High School") {
				$("#Institution_ID").val($("#High_School_ID").val());
				$("#collegeUniversityContainer").hide();
				$("#highSchoolContainer").show();
				$("#institutionContainer").hide();
				$("#departmentContainer").show();
				$("#address1Container").show();
				$("#address2Container").show();
				$("#cityContainer").show();
				$("#stateZipCodeContainer").show();
			} else if (instType == "College University") {
				$("#Institution_ID").val($("#College_University_ID").val());
				$("#collegeUniversityContainer").show();
				$("#highSchoolContainer").hide();
				$("#institutionContainer").hide();
				$("#departmentContainer").show();
				$("#address1Container").show();
				$("#address2Container").show();
				$("#cityContainer").show();
				$("#stateZipCodeContainer").show();
			} else {
				$("#Institution_ID").val(0);
				$("#collegeUniversityContainer").hide();
				$("#highSchoolContainer").hide();
				$("#institutionContainer").show();
				$("#departmentContainer").show();
				$("#address1Container").show();
				$("#address2Container").show();
				$("#cityContainer").show();
				$("#stateZipCodeContainer").show();
			}
		}
		var putCollegeUniversityID = function() {
			var cuID = $("#College_University_ID").val();
			if (isInt(cuID)) {
				$("#Institution_ID").val(cuID);
			} else {
				$("#Institution_ID").val("");
			}
		}
		var putHighSchoolID = function() {
			var hsID = $("#High_School_ID").val();
			if (isInt(hsID)) {
				$("#Institution_ID").val(hsID);
			} else {
				$("#Institution_ID").val("");
			}
		}
		var updateProductQuantityRules = function() {
			$.ajax({
				type: "GET",
				url: "/assets/csac/com/API.cfc?method=checkStock",
				data: {"productIDs": ""},
				dataType: "json",
				success: function(response) {
					productQuantityRules = response;
					for (productID in productQuantityRules) {
						var ruleContainer = $(".productQuantityRuleContainer_" + productID);
						var ruleMessage = "";
						if (isInt(parseInt(productQuantityRules[productID].MAXIMUM))) {
							if (productQuantityRules[productID].SUBCATEGORY == "Volunteer T-Shirts") {
								ruleMessage += "Maximum " + parseInt(productQuantityRules[productID].MAXIMUM) + "\<br \/\>total across\<br \/\>all sizes\<br \/\>";
							} else {
								ruleMessage += "Maximum " + parseInt(productQuantityRules[productID].MAXIMUM) + "\<br \/\>";
							}
						}
						if (isInt(parseInt(productQuantityRules[productID].INCREMENT))) {
							ruleMessage += "Increments of " + parseInt(productQuantityRules[productID].INCREMENT) + "\<br \/\>";
						}
						if (ruleMessage.length > 0) {
							ruleContainer.html(ruleMessage);
							ruleContainer.show();
						}
						
					}
				},
				error: function(jqXHR, textStatus, errorThrown) {
					//console.log(errorThrown);
				}
			})
		}
		var copyQuantities = function() {
			var productIDs = $(".productID");
			var pID = 0;
			var oPs = {};
			var msg = "";
			var msgs = {};
			var k = "";
			for (var i=0; i<productIDs.length; i++) {
				pID = productIDs[i].value;
				oPs[pID] = {};
				oPs[pID].product = productQuantityRules[pID].PRODUCT
				oPs[pID].quantity = $("#Quantity_" + pID).val();
				oPs[pID].quantityShipped_ = $("#Quantity_Shipped_" + pID).val();
				if (oPs[pID].quantityShipped_ > 0 && oPs[pID].quantityShipped_ !== oPs[pID].quantity) {
					msgs[pID] = "Quantity Shipped for " + oPs[pID].product + " is already set to " + oPs[pID].quantityShipped_ + ".\n\nIf you would like to keep the value of " + oPs[pID].quantityShipped_ + " select Cancel.\n\nIf you would like to change the value to " + oPs[pID].quantity + " select Ok.\n\nPlease note that this action does not effect any other items.";
				} else {
					$("#Quantity_Shipped_" + pID).val(oPs[pID].quantity);
				}
			}
			if (!$.isEmptyObject(msgs)) {
				for (k in msgs) {
					if (confirm(msgs[k])) {
						$("#Quantity_Shipped_" + k).val(oPs[k].quantity);
					}
				}
			}
		}
		var filePopover = function(productID) {
			//console.log(productID);
			$("#filePopover_" + productID).popover({
				placement: "auto left",
				title: "This is the popover title",
				html: "<strong>Woo hoo!</strong><br>This is the html attribute."
			});	
			$("#filePopover_" + productID).popover("show");
		}
		$(function() {
			toggleInstitution();
			updateProductQuantityRules();
			//$("#Approved_Date").datepicker();
			//$("#Shipped_Date").datepicker();
			$("#orderForm").validate(validatorConfig);
		})
	//-->
	</script>

	<style>
		small {font-size: 0.8em;}
		.orderProducts tbody td {font-size: 1.2em;}
		.copyQuantities {background-color: #fff; border: solid 0px #ddd;}
	</style>
	
	<h3 style="background-color: white; font-size: 1.6em;">Shipping Information</h3>

	<cfform id="orderForm" name="orderForm" action="index.cfm" role="form"  method="post">
		
		<input type="hidden" name="action" value="saveOrder" />
		<cfoutput>
			<cfif IsUserLoggedIn()>
				<input type="hidden" name="ui" value="#returnUI#" />
			<cfelse>
				<input type="hidden" name="ui" value="thankYou" />
			</cfif>
			<input type="hidden" id="Order_ID" name="Order_ID" value="#order.getOrder_ID()#" />
			<input type="hidden" id="Institution_ID" name="Institution_ID" value="#order.getInstitution_ID()#" />
			<div class="row">
				<div class="col-lg-4">
					<!--- <cfif order.getOrder_ID() gt 0>
						<div class="form-group">
							<label>Order ID</label>
							<input type="text" name="foo" value="#order.getOrder_ID()#" class="form-control" disabled="disabled" />
						</div>
					</cfif> --->
					<cfif IsUserLoggedIn()>
						<div class="form-group">
							<label for="Status">Status<span class="label label-info">Required</span></label>
							<select id="Status" name="Status" class="form-control" required>
								<cfloop index="s" from="1" to="#ArrayLen(statuses)#">
									<option value="#statuses[s].value#"<cfif order.getStatus() eq statuses[s].value> selected</cfif>>#statuses[s].text#</option>
								</cfloop>
							</select>
						</div>
						<cfif GetUserRoles() eq "Administrator" or GetUserRoles() eq "Manager">
							<div class="form-group">
								<div class="row">
									<div class="col-lg-6">
										<label for="First_Name">Approved Date</label>
										<input type="text" id="Approved_Date" name="Approved_Date" value="#order.getApproved_Date()#" class="form-control" required />
									</div>
									<div class="col-lg-6">
										<label for="First_Name">Shipped Date</label>
										<input type="text" id="Shipped_Date" name="Shipped_Date" value="#order.getShipped_Date()#" class="form-control" required />
									</div>
								</div>
							</div>
						<cfelse>
							<div class="form-group">
								<div class="row">
									<div class="col-lg-6">
										<label for="First_Name">Approved Date</label>
										<input type="text" id="Approved_Date" name="Approved_Date" value="#order.getApproved_Date()#" class="form-control" disabled />
									</div>
									<div class="col-lg-6">
										<label for="First_Name">Shipped Date</label>
										<input type="text" id="Shipped_Date" name="Shipped_Date" value="#order.getShipped_Date()#" class="form-control" disabled />
									</div>
								</div>
							</div>
						</cfif>
					</cfif>
					<div class="form-group">
						<label for="First_Name">First Name<span class="label label-info">Required</span></label>
						<input type="text" id="First_Name" name="First_Name" value="#order.getFirst_Name()#" class="form-control" required />
					</div>
					<div class="form-group">
						<label for="Last_Name">Last Name<span class="label label-info">Required</span></label>
						<input type="text" id="Last_Name" name="Last_Name" value="#order.getLast_Name()#" class="form-control" required />
					</div>
					<div class="form-group">
						<label for="Email">Email<span class="label label-info">Required</span></label>
						<input type="text" id="Email" name="Email" value="#order.getEmail()#" class="form-control" required />
					</div>
					<div class="form-group">
						<div class="row">
							<div class="col-lg-8">
								<label for="Phone">Phone<span class="label label-info">Required</span></label>
								<input type="text" class="form-control" id="Phone" name="Phone" value="#order.getPhone()#" placeholder="######-######-########" required  />
							</div>
							<div class="col-lg-4">
								<label for="Extension">Extension</label>
								<input type="text" id="Extension" name="Extension" value="#order.getExtension()#" class="form-control" />
							</div>
						</div>
					</div>
				</div>
				<div class="col-lg-4">
					<div class="form-group">
						<label for="Institution_Type">Institution Type<span class="label label-info">Required</span></label>
						<select id="Institution_Type" name="Institution_Type" class="form-control" onChange="toggleInstitution()" required>
							<option value="">Select...</option>
							<cfloop index="t" from="1" to="#ArrayLen(institutionTypes)#">
								<option value="#institutionTypes[t].value#"<cfif order.getInstitution_Type() eq institutionTypes[t].value> selected</cfif>>#institutionTypes[t].text#</option>
							</cfloop>
						</select>
					</div>
					<div id="collegeUniversityContainer" class="form-group" style="display: none;">
						<label for="College_University_ID">College/University<span class="label label-info">Required</span></label>
						<select id="College_University_ID" name="College_University_ID" class="form-control" onChange="putCollegeUniversityID()">
							<option value="">Select...</option>
							<cfloop query="institutions">
								<option value="#Institution_ID#"<cfif order.getInstitution_ID() eq Institution_ID> selected</cfif>>#Institution# - #FAO_City#</option>
							</cfloop>
						</select>
					</div>
					<div id="highSchoolContainer" class="form-group" style="display: none;">
						<label for="High_School_ID">High School<span class="label label-info">Required</span></label>
						<select id="High_School_ID" name="High_School_ID" class="form-control" onChange="putHighSchoolID()">
							<option value="">Select...</option>
							<cfloop query="highSchools">
								<option value="#High_School_ID#"<cfif order.getInstitution_ID() eq High_School_ID> selected</cfif>>#High_School# - #City#</option>
							</cfloop>
						</select>
					</div>
					<div id="institutionContainer" class="form-group" style="display: none;">
						<label for="Institution">Institution<span class="label label-info">Required</span></label>
						<input type="text" id="Institution" name="Institution" value="#order.getInstitution()#" class="form-control" />
					</div>
					<div id="departmentContainer" class="form-group" style="display: none;">
						<label for="Department">Department</label>
						<input type="text" id="Department" name="Department" value="#order.getDepartment()#" class="form-control" />
					</div>
					<div id="address1Container" class="form-group" style="display: none;">
						<label for="Address">Address 1<span class="label label-info">Required</span></label>
						<input type="text" id="Address1" name="Address1" value="#order.getAddress1()#" class="form-control" required />
					</div>
					<div id="address2Container" class="form-group" style="display: none;">
						<label for="Address2">Address 2</label>
						<input type="text" id="Address2" name="Address2" value="#order.getAddress2()#" class="form-control" />
					</div>
					<div id="cityContainer" class="form-group" style="display: none;">
						<label for="City">City<span class="label label-info">Required</span></label>
						<input type="text" id="City" name="City" value="#order.getCity()#" class="form-control" required />
					</div>
					<div id="stateZipCodeContainer" class="form-group" style="display: none;">
						<div class="row">
							<div class="col-lg-6">
								<label for="State">State</label>
								<select id="State" name="State" class="form-control">
									<cfloop query="states">
										<option value="#Abbreviation#"<cfif order.getState() eq Abbreviation> selected</cfif>>#State#</option>
									</cfloop>
								</select>
							</div>
							<div class="col-lg-6">
								<label for="Zip_Code">Zip&nbsp;Code<span class="label label-info">Required</span></label>
								<input type="text" id="Zip_Code" name="Zip_Code" maxlength="5" value="#order.getZip_Code()#" class="form-control" placeholder="##########" required />
							</div>
						</div>
					</div>
				</div>
				<div class="col-lg-4">
					<div class="form-group">
						<label for="Shipping_Instructions">Shipping&nbsp;Instructions</label>
						<textarea class="form-control" id="Shipping_Instructions" name="Shipping_Instructions" rows="3">#order.getShipping_Instructions()#</textarea>
					</div>
					<div class="form-group">
						<label for="Shared_Notes">Notes</label>
						<textarea class="form-control" id="Shared_Notes" name="Shared_Notes" rows="3">#order.getShared_Notes()#</textarea>
					</div>
					<cfif IsUserLoggedIn()>
						<div class="form-group">
							<label for="Private_Notes">Private Notes</label>
							<textarea class="form-control" id="Private_Notes" name="Private_Notes" rows="3">#order.getPrivate_Notes()#</textarea>
						</div>
						<div class="form-group">
							<label for="Tracking">Tracking Codes (one per line)</label>
<textarea class="form-control" id="Tracking_Codes" name="Tracking_Codes" rows="3">
<cfloop query="trackings">
#Tracking_Code#
</cfloop>
</textarea>
						</div>
					<cfelseif order.getOrder_ID() gt 0>
						<div class="form-group">
							<label for="Tracking">Tracking Codes</label>
							<p>
								<cfif trackings.RecordCount gt 0>
									<cfloop query="trackings">
										<a href="https://www.fedex.com/fedextrack/?tracknumbers=#Tracking_Code#">#Tracking_Code#</a><br />
									</cfloop>
								<cfelse>
									No tracking codes
								</cfif>
							</p>
						</div>
					</cfif>
				</div>
			</div>
		</cfoutput>
		<div class="row">
			<div class="col-lg-12">
				<table class="table table-striped orderProducts">
					<cfoutput query="products" group="Category">
						<cfif (order.getOrder_ID() eq 0 and ListFind(hiddenCategories, Product_Category_ID) eq 0) OR order.getOrder_ID() gt 0>
							<cfoutput group="Subcategory">
								<thead>
									<tr style="border-color: white;">
										<th colspan="2"><h3 style="background-color: white; font-size: 1.6em;">#Category#<cfif Len(Subcategory) gt 0> - #Subcategory#</cfif></h3></th>
										<th class="col140">Quantity</th>
										<cfif IsUserLoggedIn() OR order.getOrder_ID() gt 0>
											<th class="col140">
												Quantity Shipped
											</th>
										</cfif>
									</tr>
								</thead>
								<!--- <thead>
									<tr>
										<th colspan="2" style="border-bottom: solid 1px ##ddd;"><h3 style="background-color: white; font-size: 1.6em;">#Category#<cfif Len(Subcategory) gt 0> - #Subcategory#</cfif></h3></th>
										<th class="col140" style="border: solid 1px ##ddd;">Quantity</th>
										<cfif IsUserLoggedIn() OR order.getOrder_ID() gt 0>
											<th class="col140" style="border: solid 1px ##ddd;">
												Quantity Shipped
											</th>
										</cfif>
									</tr>
								</thead> --->
								<tbody>
									<cfoutput>
										<cfif order.getOrder_ID() gt 0 and Order_Product_ID gt 0>
											<cfset orderProductID = Order_Product_ID />
										<cfelse>
											<cfset orderProductID = 0 />
										</cfif>
										<cfif Download_Only eq 0 and (Inventory eq 0 or Stock gt 0 or Allow_Back_Order eq 1)>
											<cfset canOrder = true />
										<cfelse>
											<cfset canOrder = false />
										</cfif>
										<input type="hidden" id="Order_Product_ID" name="Order_Product_ID" value="#orderProductID#" class="orderProductID" />
										<input type="hidden" id="Product_ID" name="Product_ID" value="#Product_ID#" class="productID" />
										<cfset productImages = request.Base.getProductImages(productIDs = Product_ID) />
										<cfset productFiles = request.Base.getProductFiles(productIDs = Product_ID) />
										<tr>
											<td class="col100p" style="vertical-align: top;">
												<cfif productImages.RecordCount gt 0 and NOT IsUserLoggedIn()>
													<!--- thumbnails should be no more than 70px wide --->
													<cfimage action="info" source="#productImages.Directory#\#productImages.Name#" structname="imageProps">
													<cfset w = 70 />
													<cfset wm = imageProps.width/w />
													<cfset h = imageProps.height/wm />
													<a href="/common/images/products/#productImages.Name#" target="_blank"><img src="/common/images/products/#productImages.Name#" width="#w#" height="#h#" align="left" style="margin-right: 10px;" /></a>
												</cfif>
												#Product#<br />
												<small>#Description#<cfif Len(Trim(Description)) gt 0> </cfif>#ID#</small>
											</td>
											<td class="col80" style="text-align: center; vertical-align: middle;">
												<cfif productFiles.RecordCount gt 0>
													<a href="/common/files/products/#productFiles.Name#" target="_blank"><span class="icon-download-alt" style="font-size: 3em;"></span></a><br />
													<small>Download</small>
												<cfelseif Download_Only eq 1>
													<a href="##" onclick="alert('File currently unavailable.\n\nPlease check back.'); return false;"><span class="icon-download-alt" style="font-size: 3em;"></span></a><br />
													<small>Download</small>
												</cfif>
											</td>
											<cfif order.getOrder_ID() eq 0>
												<cfset qty = 0 />
											<cfelse>
												<cfset qty = Quantity />
											</cfif>
											<td style="vertical-align: middle; text-align: center;">
												<cfif order.getOrder_ID() eq 0>
													<cfif canOrder>
														<input type="text" id="Quantity_#Product_ID#" name="Quantity_#Product_ID#" value="#qty#" class="form-control center-block quantity" />
														<small class="productQuantityRuleContainer_#Product_ID#" style="display: none; margin-top: 8px;"></small>
													<cfelse>
														<input type="hidden" id="Quantity_#Product_ID#" name="Quantity_#Product_ID#" value="#qty#" class="quantity" />
														<cfif Download_Only eq 1>
															<small>Download only</small>
														<cfelseif Inventory eq 1 and Stock lte 0 and Allow_Back_Order eq 0>
															<small>Out of stock</small>
														</cfif>
													</cfif>
												<cfelse>
													<input type="hidden" id="Quantity_#Product_ID#" name="Quantity_#Product_ID#" value="#qty#" class="quantity" />
													#qty#
												</cfif>
											</td>
											<cfif order.getOrder_ID() eq 0>
												<cfset qtyShipped = 0 />
											<cfelse>
												<cfset qtyShipped = Quantity_Shipped />
											</cfif>
											<cfif IsUserLoggedIn()>
												<td style="vertical-align: middle; text-align: center;">
													<cfif Download_Only eq 1 OR (Inventory eq 1 and Stock lte 0 and Allow_Back_Order eq 0)>
														<input type="hidden" id="Quantity_Shipped_#Product_ID#" name="Quantity_Shipped_#Product_ID#" value="#qtyShipped#" class="quantityShipped" />
													<cfelseif order.getOrder_ID() eq 0 OR NOT IsDate(Shipped_Date)>
														<input type="text" id="Quantity_Shipped_#Product_ID#" name="Quantity_Shipped_#Product_ID#" value="#qtyShipped#" class="form-control center-block quantityShipped" required />
														<small class="productQuantityRuleContainer_#Product_ID#" style="display: none; margin-top: 8px;"></small>
													
													<cfelse>
														<input type="hidden" id="Quantity_Shipped_#Product_ID#" name="Quantity_Shipped_#Product_ID#" value="#qtyShipped#" class="quantityShipped" />
														#qtyShipped#
													</cfif>
												</td>
											<cfelseif order.getOrder_ID() gt 0>
												<td style="vertical-align: middle; text-align: center;">
													<input type="hidden" id="Quantity_Shipped_#Product_ID#" name="Quantity_Shipped_#Product_ID#" value="#qtyShipped#" class="quantityShipped" />
													#qtyShipped#
												</td>
											<cfelse>
												<input type="hidden" id="Quantity_Shipped_#Product_ID#" name="Quantity_Shipped_#Product_ID#" value="#qtyShipped#" class="quantityShipped" />
											</cfif>
										</tr>
									</cfoutput>
								</tbody>
							</cfoutput>
						</cfif>
					</cfoutput>
				</table>
			</div>
		</div>
		<cfoutput>
			<div class="row">
				<div class="col-lg-12">
					<div class="well well-sm" style="width: 100%;">
						<cfif IsUserLoggedIn()>
							<a href="?ui=#returnUI#" class="btn btn-info">Cancel</a>
							<button type="submit" id="saveButton" name="saveButton" class="btn btn-info input">Save</button>
						<cfelse>
							<button type="submit" id="submitOrderButton" name="submitOrderButton" class="btn btn-info input">Submit Order</button>
						</cfif>
					</div>
				</div>
			</div>
		</cfoutput>
	</cfform>

<cfelse>
	<div class="alert alert-info">Order not found</div>
</cfif>

